#pragma once

#include "object.h"
#include <vector>


class Cylinder : public Object
{
public :
  // Set default parameters. Radius is 1.0, position is 0,0,0.
  Cylinder();
  virtual ~Cylinder() {}

  // Accessors
  float bottomRadius() const { return bottomRadius_; }
  void setBottomRadius(float radius) { bottomRadius_ = radius; }

  float topRadius() const { return topRadius_; }
  void setTopRadius(float radius) { topRadius_ = radius; }

  // Set both top and bottom radii :
  void setRadius(float radius) {bottomRadius_ = radius; topRadius_ = radius;}

  float height() const { return height_; }
  void setHeight(float height) { height_ = height; }

  // Draw using OpenGL
  virtual void draw() const;

  // Get the intersection radius information
  virtual float boundingRadius() const {
    float max = ( bottomRadius_> topRadius_) ? bottomRadius_ : topRadius_;
    max = (max < height_) ? height_ : max;
    return max;
}

  // Does the ray r intersect the Cylinder
  virtual bool intersect(const Ray&, Hit& hit) const;

  // Parse XML
  virtual void initFromDOMElement(const QDomElement& e);

private:
  // Init elements after DOM callback
  void init(float radius, int ntheta, int nphi) ;

  // Radius of the Cylinder
  float bottomRadius_;
  float topRadius_;
  float height_;
};
